#include "EquationSolver.hpp"
#include "Function.hpp"
#include <iostream>
#include <cmath>


const double Pi = acos(-1.);
class F1 : public Function {
	public:
		double operator() (double x) const {
			return sin(x/2)-1 ;
		}
};

void solve_f1() {
        std::cout << "Solving sin(x/2)-1 with x_0=0,x_1=Pi/2" << std::endl;
        Secant_Method solver_f1(F1(), Pi/2,Pi);
        double x = solver_f1.solve();
        std::cout << "A root is: " << x << std::endl;
}

class F2 : public Function {
        public:
                double operator() (double x) const {
                        return exp(x)-tan(x); 
                }  
};

void solve_f2() {                                                          
        std::cout << "Solving exp(x)-tan(x) with x_0=1,x_1=1.4" << std::endl;                                             
        Secant_Method solver_f2(F2(), 1.4,1.8);
	double x = solver_f2.solve();
        std::cout << "A root is: " << x << std::endl;
}
class F3 : public Function {
        public:
                double operator() (double x) const {
			return std::pow(x,3)-12*std::pow(x,2)+3*x+1;
                }  
};

void solve_f3() {                                                          
        std::cout << "Solving x^3-12x^2+3x+1 with x_0=0,x_1=-0.5" << std::endl;                                             
        Secant_Method solver_f3(F3(), 0,0.5);
        double x = solver_f3.solve();
        std::cout << "A root is: " << x << std::endl;
}

int main() {
    solve_f1();
    solve_f2();
    solve_f3();
     return 0;
}
